package com.own.business.question.entity.po;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.own.business.question.common.base.ReplyEnvironment;
import com.own.business.question.common.handler.ReplyEnvironmentHandler;
import com.own.component.common.base.entity.po.BasePo;
import com.own.constant.ConstantBeanSuffix;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * Practice
 *
 * @author chenxueli
 * @date 2021/05/14 15:49:28
 */
@Schema(description = "练习表" + ConstantBeanSuffix.PO)
@Getter
@Setter
@ToString
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "practice", autoResultMap = true)
public class Practice extends BasePo {

    @Schema(description = "目标内容id")
    private Long fkTargetId;

    @Schema(description = "用户id")
    private Long fkUserId;

    @Schema(description = "题目数量")
    private Integer questionNumber;

    @Schema(description = "作答环境")
    @TableField(typeHandler = ReplyEnvironmentHandler.class)
    private ReplyEnvironment replyEnvironment;

    @Schema(description = "作答状态 0=未作答 1=已作答 2=保存 3=废弃")
    private Integer status;

    @Schema(description = "用时（ms）")
    private Long useTime;

    @Schema(description = "分数")
    private BigDecimal score;

    @Schema(description = "获取练习的时间")
    private LocalDateTime refreshTime;

    @Schema(description = "提交练习的时间")
    private LocalDateTime submitTime;

    /**
     * 强制初始化
     */
    @Override
    public void init() {
        super.init();
        score = BigDecimal.ZERO;
        useTime = 0L;
        questionNumber = 0;
        refreshTime = LocalDateTime.now();
        status = Status.NO_ANSWER;
    }

    /**
     * 作答状态
     */
    public interface Status {
        /**
         * 未作答
         */
        int NO_ANSWER = 0;
        /**
         * 已作答
         */
        int ANSWER = 1;
        /**
         * 保存
         */
        int SAVE = 2;
        /**
         * 废弃
         */
        int ABANDON = 3;
    }
}
